package org.borg.homepage.controller

import javax.servlet.http.HttpServletRequest

import org.slf4j.{Logger, LoggerFactory}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation._
import org.vox.homepage.service.HomepageService

/**
  * @author Borg.lee
  */
@RestController
class HomepageController {

  import HomepageController.logger

  @Autowired
  var service: HomepageService = _

  /**
    *
    * @param request HttpServletRequest
    * @return
    */
  @RequestMapping(value = Array("/index"), method = Array(RequestMethod.GET))
  @ResponseBody
  def index(request: HttpServletRequest): String = {
    "index"
  }

  /**
    *
    * @param request HttpServletRequest
    * @return
    */
  def login(request: HttpServletRequest): Unit = {
    if (logger.isDebugEnabled()) {
      logger.debug("login is process, request: {}", request)
    }
    val username = request.getParameter("username")
    val password = request.getParameter("password")
    service.login(username, password)
  }
}

object HomepageController {
  val logger: Logger = LoggerFactory.getLogger(classOf[HomepageController])
}